<template>
	<view class="home">
		<navbar></navbar>
		<tab :list="tabList" :tabIndex="tabIndex" @tab="tab" @getTotalHeight="getHeight"></tab>
		<view class="home-list" style="background: gainsboro;">
			<view :class="ad_style">
				<button class="close" @click="close">关闭</button>
				<image src="https://s2.loli.net/2024/01/10/5SCst4xceTmXEGJ.webp" class="ad_img" @click="nav"></image>
				<!-- https://i.postimg.cc/7LSgc4Ky/ad1.webp -->
			</view>
			<list :tab="tabList" :activeIndex="activeIndex" @changed="change"></list>
		</view>
	</view>
</template>

<script>
	import {
		getLabel
	} from '@/common/mock/mock.js';
	import {
		config
	} from '@/common/config.js';
	import formItem from '../../uni_modules/uview-ui/libs/config/props/formItem';
	export default {
		data() {
			return {
				tabList: [],
				tabIndex: 0,
				activeIndex: 0,
				ad_style: 'ad1',
			}
		},
		onLoad() {
			this.getLabel();
		},
		methods: {
			nav(){
				uni.navigateTo({
					url:"/pages/webView/webView"
				})
			},
			close() {
				this.ad_style = 'ad2'
				this.close_style = 'close2'
			},
			change(current) {
				// console.log("当前swiper的值:",current);
				this.tabIndex = current;
				this.activeIndex
			},
			tab({
				data,
				index
			}) {
				// console.log(data, index)
				this.activeIndex = index;
			},
			getLabel() {
				// mock数据
				// getLabel().then((res) => {
				// 	// console.log(res)
				// 	// data.unshit({
				// 	// 	name: '全部'
				// 	// })
				// 	this.tabList = res
				// })
				// #ifdef APP-PLUS
				uniCloud云函数
				this.$api.get_label({
					name: 'get_label'
				}).then((res) => {
					const {
						data
					} = res
					// console.log('标签',data);
					data.unshift({
						name: '全部'
					})
					this.tabList = data
				})
				// #endif


				// #ifndef APP-PLUS
				uni.request({
					url: config.url + 'label/list',
					success: (res) => {
						// console.log(res)
						const {
							data
						} = res.data
						// console.log('标签',data);
						data.unshift({
							name: '全部'
						})
						this.tabList = data
					}
				})
				// #endif
				// 后端请求

			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.ad1 {
		position: absolute;
		right: 40rpx;
		top: 220rpx;
		// height: 700rpx;
		width: 50%;
		animation: myfirst 10s linear infinite;
		/* Safari 与 Chrome: */
		-webkit-animation: myfirst 10s linear  infinite;
		z-index: 999;
		border-radius: 20rpx;
		border-color: black;
	}

	.ad2 {
		position: absolute;
		right: 40rpx;
		top: 220rpx;
		height: 700rpx;
		width: 50%;
		animation: slide-out-top 1s;
		animation-fill-mode: forwards;
		/* Safari 与 Chrome: */
		z-index: 998;
		border-radius: 20rpx;
		border-color: black;
	}

	.close {
		position: relative;
		float: right;
		right: 0rpx;
		top: 0rpx;
		width: 150rpx;
		height: 80rpx;
		font-size: 30rpx;
		font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
	}

	.ad_img {
		float: left;
		top: 0rpx;
		width: 97%;
		height: 600rpx;
		border-radius: 20rpx;
		z-index: 999;
		background-color: white;
		margin: 20rpx;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: hidden;

		.home-list {
			flex: 1;
			box-sizing: border-box;
			// border: 1px red solid;
		}
	}
</style>